import DBUtil
import openpyxl
# 打开一个excel文件
wb = openpyxl.load_workbook('链家.xlsx')
ws = wb.active
def getDataFromDB():
    '''
    从数据库获取数据(biaoti表)
    :return:
    '''
    sql = 'select name , url , quyu, jieshao , zongjia , pingfang from biaoti'
    result = DBUtil.query(sql) # 元组
    # write2Excel(result)
    print(result)
    write2Excel(list(result))

def write2Excel(result):
    # ws = wb.create_sheet(topTitle)
    for row in result:
        ws.append(row)
    wb.save('链家.xlsx')

if __name__ == '__main__':
    getDataFromDB()
